package com.newlink.building.userinfo.activity

import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.newlink.building.common_base.base.NL_BaseMvpActivity
import com.newlink.building.common_base.model.bean.FamilyManagementListData1
import com.newlink.building.common_base.widget.CustomDialog
import com.newlink.building.userinfo.R
import com.newlink.building.userinfo.databinding.ActivityFamilyManagementDetailAddFailEmailBinding
import com.newlink.building.userinfo.mvp.Module_UserInfo_FamilyManagementDetailAddFailEmailPresenter
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_FamilyManagementDetailAddFailEmailContract

/**
 * @author wangyang
 * @date 2022/10/12
 * @description 我的——家庭管理——添加失败状态的详情页（邮箱）页面
 */
class Module_UserInfo_FamilyManagementDetailAddFailEmailActivityNL :
    NL_BaseMvpActivity<Module_UserInfo_FamilyManagementDetailAddFailEmailContract.View, Module_UserInfo_FamilyManagementDetailAddFailEmailContract.Presenter>(),
    Module_UserInfo_FamilyManagementDetailAddFailEmailContract.View, View.OnClickListener {

    var name: String? = null
    var phone: String? = null

    companion object {
        /**
         * 对外开放统一入口
         *
         * @param context
         * @param url     name
         * @param title   phone
         */
        fun startSelf(context: Context?, name: String, phone: String) {
            val intent =
                Intent(context, Module_UserInfo_FamilyManagementDetailAddFailEmailActivityNL::class.java)
            intent.putExtra("name", name)
            intent.putExtra("phone", phone)
            context?.startActivity(intent)
        }
    }

//    override fun attachLayoutRes(): Int =
//        R.layout.activity_family_management_detail_add_fail_email

    private lateinit var mBinding: ActivityFamilyManagementDetailAddFailEmailBinding
    override fun attachLayoutRes(): View {
        mBinding = ActivityFamilyManagementDetailAddFailEmailBinding.inflate(layoutInflater)
        return mBinding.root
    }

    override fun initData() {
        name = intent?.getStringExtra("name")
        phone = intent?.getStringExtra("phone")
    }

    override fun initView() {
        findViewById<TextView>(R.id.tv_title_bar_center).text =
            resources.getText(R.string.family_management_detail_title)
        findViewById<ImageView>(R.id.iv_title_bar_right).setBackgroundResource(R.mipmap.title_bar_delete)
        findViewById<ImageView>(R.id.iv_title_bar_right).visibility = View.VISIBLE
        findViewById<ImageView>(R.id.iv_title_bar_right).setOnClickListener(this)

        mBinding.tvName.text = name
        mBinding.tvPhone.text = phone
        mBinding.btnReAdd.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.iv_title_bar_right -> {
                //删除
                CustomDialog(this).setMessage(getString(R.string.family_management_delete))
                    .setPositiveButton(object : CustomDialog.OnClickListener {
                        override fun onClick(dialog: CustomDialog) {
                            dialog.dismiss()
                        }
                    }).setNegativeButton(object : CustomDialog.OnClickListener {
                        override fun onClick(dialog: CustomDialog) {
                            dialog.dismiss()
                        }
                    }).show()
            }

            R.id.btn_re_add -> {
                //重新添加
                startActivity(Intent(this, Module_UserInfo_FamilyManagementAddActivityNL::class.java))
            }
        }
    }

    override fun createPresenter(): Module_UserInfo_FamilyManagementDetailAddFailEmailContract.Presenter =
        Module_UserInfo_FamilyManagementDetailAddFailEmailPresenter()

    override fun showData(list: MutableList<FamilyManagementListData1>) {
    }
}